package com.zlq.cn

import com.alibaba.fastjson.JSON
import org.apache.commons.io.FileUtils
import org.jsoup.Jsoup
import java.io.File

data class ImomoeMain(
        val mSlider: MutableList<ImomoeSlider> = mutableListOf(),
)

data class ImomoeSlider(
        val image: String,
        val link: String,
        val desc: String,
)

data class FlowerLanguageGroup(
        val name: String,
        var tips: String? = null,
        var flowerLanguages: MutableList<FlowerLanguage>? = null,
)

data class FlowerLanguage(
        val name: String,
        val image: String,
        val descs: MutableList<String>,
)

fun main() {
    val rootDocument = Jsoup.parse(FileUtils.readFileToString(File("C:\\Users\\asus\\Desktop\\huayu.html"), "UTF-8"))
    val flowerLanguageGroups = rootDocument.select(".flower-nav a").map { FlowerLanguageGroup(it.text()) }
    rootDocument.select(".flower")
            .mapIndexed { index, flower ->
                flowerLanguageGroups[index].apply {
                    tips = flower.selectFirst(".tips")?.text() ?: ""
                    flowerLanguages = flower.select("li")
                            .mapTo(mutableListOf()) {
                                FlowerLanguage(
                                        it.selectFirst("h4")!!.text(),
                                        "http:${it.selectFirst("img")!!.attr("src")}",
                                        it.select("p").mapTo(mutableListOf()) { it.text() }
                                )
                            }
                }

            }
    println(JSON.toJSONString(flowerLanguageGroups))
    //println(rootDocument)

//    println(mAgefansDetails)
}
